import 'dart:async';
import 'dart:convert';
import 'dart:ui';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:chewie/chewie.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:panda/base/Constant.dart';
import 'package:panda/base/SignType.dart';
import 'package:panda/base/application.dart';
import 'package:panda/entity/gallery_entity.dart';
import 'package:panda/goods/sku_dialog.dart';
import 'package:panda/home/MyShopCar.dart';
import 'package:panda/http/Api.dart';
import 'package:panda/http/HttpUtil.dart';
import 'package:panda/order/OrderPay.dart';
import 'package:panda/order/UserVipOrderPay.dart';
// import 'package:panda/login/Welcome.dart';
// import 'package:panda/set/FillAuthCode.dart';
import 'package:panda/util/AppSaveInfoUtil.dart';
import 'package:panda/util/LoadingUtil.dart';
import 'package:panda/util/SignUtil.dart';
import 'package:provider/provider.dart';
import 'package:video_player/video_player.dart';
import '../base/Constant.dart';
import 'BuyGoods.dart';
import 'GoodsDetailsModel.dart';
import 'SkuProvider.dart';

class UserVipGoodsDetailPage extends StatefulWidget {
  String goods_id = "";
  String img;
  int type = 0; //默认非抢购
  String id = "0";
  String start_time = "",
      end_time = "",
      limit_num = "",
      all_num = "",
      sale_num = "",
      price = "0",
      old_price = "";
  UserVipGoodsDetailPage(
      {Key key,
      @required this.goods_id,
      @required this.img,
      this.type,
      this.id,
      this.all_num,
      this.price,
      this.old_price,
      this.end_time,
      this.limit_num,
      this.sale_num,
      this.start_time})
      : super(key: key);

  _UserVipGoodsDetailPageState createState() => _UserVipGoodsDetailPageState();
}

class _UserVipGoodsDetailPageState extends State<UserVipGoodsDetailPage> {
  double appBarAlpha = 0;
  SkuProvider skuProvider;
  Object price = "";
  Object old_price = "";
  String goods_name = "", lv_price = "", is_send = "Y";
  String html = "";
  List<GalleryModel> gallery = List();
  bool hasSku = false;
  int count = 0;
  int goods_num = 1;
  String token = "", comment_num = "0", lvl1_cent = "0";
  Map<String, dynamic> skuMap = {"skus": [], "goods": []};
  GoodsDetailsModel goodsDetailsModel;
  Timer _timerIndex;
  String _day1 = '';
  String description = '';
  String _hour1 = '';
  String _minute1 = '';
  String video;
  String _second1 = '', origin_goods_id = "1", sales_num = "0";
  bool isCollectGoods = false;
  ChewieController chewieController;
  VideoPlayerController videoPlayerController;
  _onScroll(offset) {
    double alpha = offset / 50;
    if (alpha < 0) {
      alpha = 0;
    } else if (alpha > 1) {
      alpha = 1;
    }
    setState(() {
      appBarAlpha = alpha;
    });
  }

  @override
  void dispose() {
    if (videoPlayerController != null) {
      videoPlayerController.dispose();
      chewieController.dispose();
    }
    _timerIndex.cancel();
    _timerIndex = null;
    super.dispose();
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getString(TOKEN).then((value) {
      token = value;
    });
    if (widget.type == 1) {
      _timeFunc(widget.end_time);
    }
    GalleryModel model = new GalleryModel(img: widget.img);
    gallery.add(model);
    count = 1;
    goodsDetailsModel = GoodsDetailsModel.fromJson(skuMap);
    skuProvider = SkuProvider(goodsDetailsModel);
    var list =
        goodsDetailsModel.goods.map((item) => item.attribute_name).toList();
    skuProvider.selectedSku = "请选择\t${list.join("，")}";
    getGoodsDetail();
  }

  getGoodsDetail() async {
    Map map = new Map();
    map['goods_id'] = widget.goods_id;
    map['id'] = widget.goods_id;
    map['token'] = token;
    map['sign_type'] = SignType.GET_GOODS_DETAIL;
    Response<String> response = await HttpUtil().post(
        Api.BaseUrl + "/index.php/wap/UserGoods/getMsg",
        data: getSign(map));
    print(response);
    Map userMap = json.decode(response.data);
    int code = userMap['code'];
    if (code == 1 && mounted) {
      gallery.clear();
      if (widget.type == 1) {
        if (userMap['data']['goodsMsg']['imglist'] == null ||
            (userMap['data']['goodsMsg']['imglist'] as List).length == 0) {
          GalleryModel model = new GalleryModel(
              img: userMap['data']['goodsMsg']['detail']['img']
                  .toString()
                  .replaceAll("\\", "/"));
          gallery.add(model);
        } else {
          (userMap['data']['goodsMsg']['imglist'] as List).forEach((v) {
            gallery.add(new GalleryModel.fromJson(v));
          });
        }
        origin_goods_id =
            userMap['data']['goodsMsg']['detail']['goods_id'].toString();
        sales_num =
            userMap['data']['goodsMsg']['detail']['sales_volume'].toString();
        html = userMap['data']['goodsMsg']['detail']['content'] == null
            ? ""
            : userMap['data']['goodsMsg']['detail']['content'];
        description =
            userMap['data']['goodsMsg']['detail']['description'].toString();
        video = userMap['data']['goodsMsg']['detail']['video'];
        if (video != null && video != "") {
          videoPlayerController = VideoPlayerController.network(
              Api.ImgBaseUrl + video.replaceAll("\\", "/"));
          chewieController = ChewieController(
            videoPlayerController: videoPlayerController,
            aspectRatio: 1 / 1,
            autoPlay: true,
            looping: true,
          );
        }
      } else {
        html = userMap['data']['goodsMsg']['content'] == null
            ? ""
            : userMap['data']['goodsMsg']['content']
                .toString()
                .replaceAll("\\", "/");
        origin_goods_id = widget.goods_id;
        sales_num = userMap['data']['goodsMsg']['sales_volume'].toString();
        is_send = userMap['data']['goodsMsg']['is_send'].toString();
        video = userMap['data']['goodsMsg']['video'];
        if (video != null && video != "") {
          videoPlayerController = VideoPlayerController.network(
              Api.ImgBaseUrl + video.replaceAll("\\", "/"));
          chewieController = ChewieController(
            videoPlayerController: videoPlayerController,
            aspectRatio: 1 / 1,
            autoPlay: true,
            looping: true,
          );
        }
        description = userMap['data']['goodsMsg']['description'].toString();
        if (userMap['data']['imglist'] == null ||
            (userMap['data']['imglist'] as List).length == 0) {
          GalleryModel model = new GalleryModel(
              img: userMap['data']['goodsMsg']['img']
                  .toString()
                  .replaceAll("\\", "/"));
          gallery.add(model);
        } else {
          (userMap['data']['imglist'] as List).forEach((v) {
            gallery.add(new GalleryModel.fromJson(v));
          });
        }
      }
      setState(() {
        count = gallery.length;
      });
      setState(() {
        goods_name = userMap['data']['goodsMsg']['goods_name'];

        price = userMap['data']['goodsMsg']['price'];
        old_price = userMap['data']['goodsMsg']['old_price'];
        lv_price = userMap['data']['goodsMsg']['lv_price'].toString();
        // print(userMap['data']['goodsMsg']['sku_arr'] ?? "");
        // print((userMap['data']['skulist'].toString()) ?? "");
        if (widget.type == 1) {
          hasSku = false;
          setState(() {});
          return;
        }
        if (userMap['data']['skulist'] != null &&
            (userMap['data']['skulist'] as List).length > 0) {
          setState(() {
            hasSku = false;
            skuMap['skus'] = userMap['data']['skulist'];
            skuMap['goods'] = userMap['data']['goodsMsg']['sku_arr'];
            goodsDetailsModel = GoodsDetailsModel.fromJson(skuMap);
            skuProvider = SkuProvider(goodsDetailsModel);
            var list = goodsDetailsModel.goods
                .map((item) => item.attribute_name)
                .toList();
            skuProvider.selectedSku = "请选择\t${list.join("，")}";
          });
        } else {
          setState(() {
            hasSku = false;
          });
        }
        // addZuji();
        // isCollect();
        // loadGoodsComment();
        // getCommentCount();
      });
    }
  }

  void _timeFunc(time) {
    var _newDate = DateTime.now();
    const period = const Duration(seconds: 1);
    var _diffDate = DateTime.parse(time.toString());
    _timerIndex = Timer.periodic(period, (timer) {
      //到时回调
      _diffDate = _diffDate.subtract(Duration(seconds: 1));
      // count++;
      if (_diffDate.difference(_newDate).inSeconds <= 0) {
        //取消定时器，避免无限回调
        timer.cancel();
        timer = null;
      }
      // print();
      var _surplus = _diffDate.difference(_newDate);
      int _day = (_surplus.inSeconds ~/ 3600) ~/ 24;
      int hour = (_surplus.inSeconds ~/ 3600) % 24;
      int minute = _surplus.inSeconds % 3600 ~/ 60;
      int second = _surplus.inSeconds % 60;
      // formatTime(hour) + ":" + formatTime(minute) + ":" + formatTime(second);
      setState(() {
        _day1 = _day.toString() ?? '0';
        _hour1 = hour.toString() ?? '0';
        _minute1 = minute.toString() ?? '0';
        _second1 = second.toString() ?? '0';
        _day1 = _day1.length > 1 ? _day1 : ("0" + _day1);
        _hour1 = _hour1.length > 1 ? _hour1 : ("0" + _hour1);
        _minute1 = _minute1.length > 1 ? _minute1 : ("0" + _minute1);
        _second1 = _second1.length > 1 ? _second1 : ("0" + _second1);
        // _text = _diffDate.weekday.toString()+'  ' +_diffDate.hour.toString()+':' + _diffDate.minute.toString() +':'+ _diffDate.second.toString();
      });
      // debugPrint(_text);
    });
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context);

    return new Scaffold(
      appBar: new AppBar(
        title: Text('会员商品详情',
            style: TextStyle(
                fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE),
                color: Colors.black)),
        backgroundColor: Colors.white,
        brightness: Brightness.light,
        centerTitle: true,
        iconTheme: new IconThemeData(color: Colors.black),
        elevation: 0.5,
        // actions: <Widget>[
        //   GestureDetector(
        //     child: Image.asset("images/icon_nav_share.png"),
        //   )
        // ],
      ),
      body: ChangeNotifierProvider.value(
          value: skuProvider,
          child: Consumer<SkuProvider>(builder: (context, provider, _) {
            return new Column(
              children: <Widget>[
                Expanded(
                  child: Container(
                      child: new Scrollbar(
                    child: new SingleChildScrollView(
                      child: new Container(
                        child: new Column(
                          children: <Widget>[
                            Stack(
                              children: <Widget>[
                                Container(
                                  height: MediaQuery.of(context).size.width,
                                  child: Swiper(
                                    containerHeight:
                                        MediaQuery.of(context).size.width,
                                    itemHeight:
                                        MediaQuery.of(context).size.width,
                                    itemBuilder:
                                        (BuildContext context, int index) {
                                      return new ClipRRect(
                                        child: chewieController != null &&
                                                index == 0
                                            ? Container(
                                                height: MediaQuery.of(context)
                                                    .size
                                                    .width,
                                                child: Chewie(
                                                  controller: chewieController,
                                                ))
                                            : gallery[chewieController != null
                                                            ? index - 1
                                                            : index]
                                                        .img ==
                                                    ""
                                                ? Image.asset(
                                                    'images/app_icon.png',
                                                    fit: BoxFit.fill,
                                                  )
                                                : gallery[chewieController !=
                                                                null
                                                            ? index - 1
                                                            : index]
                                                        .img
                                                        .contains("upload")
                                                    ? CachedNetworkImage(
                                                        imageUrl: Api.BaseUrl +
                                                            gallery[chewieController !=
                                                                        null
                                                                    ? index - 1
                                                                    : index]
                                                                .img,
                                                        fit: BoxFit.fill,
                                                      )
                                                    : CachedNetworkImage(
                                                        imageUrl: Api
                                                                .ImgBaseUrl +
                                                            gallery[chewieController !=
                                                                        null
                                                                    ? index - 1
                                                                    : index]
                                                                .img,
                                                        fit: BoxFit.fill,
                                                      ),
                                        borderRadius:
                                            BorderRadius.circular(0.0),
                                      );
                                    },
                                    itemCount: chewieController != null
                                        ? count + 1
                                        : count,
                                    pagination: new SwiperPagination(
                                        builder: DotSwiperPaginationBuilder(
                                            color: Colors.grey,
                                            activeColor: mainColor,
                                            size: 7.0,
                                            activeSize: 7.0)),
                                    scrollDirection: Axis.horizontal,
                                    autoplay:
                                        chewieController != null ? false : true,
                                    onTap: (index) {
                                      // Navigator.of(context)
                                      //     .push(new MaterialPageRoute(builder: (context) {
                                      //   return new HomeWebview(
                                      //     article_id: bannerData[index].img,
                                      //     title: bannerData[index].title,
                                      //   );
                                      // }));
                                    },
                                  ),
                                ),
                                // Positioned(
                                //     child: Offstage(
                                //       offstage: widget.type == 0 ||
                                //           widget.type == -1 ||
                                //           widget.type == null,
                                //       child: Container(
                                //           color: white,
                                //           alignment: Alignment.centerRight,
                                //           padding: EdgeInsets.fromLTRB(
                                //               ScreenUtil.getInstance()
                                //                   .setHeight(DP_15),
                                //               ScreenUtil.getInstance()
                                //                   .setHeight(DP_10),
                                //               ScreenUtil.getInstance()
                                //                   .setHeight(DP_15),
                                //               (ScreenUtil.getInstance()
                                //                   .setHeight(DP_10))),
                                //           child: Column(
                                //               crossAxisAlignment:
                                //                   CrossAxisAlignment.end,
                                //               children: <Widget>[
                                //                 Text("距离活动结束",
                                //                     style: TextStyle(
                                //                       fontSize: ScreenUtil
                                //                               .getInstance()
                                //                           .setSp(
                                //                               MINI_FONT_SIZE),
                                //                       color: mainColor,
                                //                     )),
                                //                 Container(
                                //                     padding:
                                //                         EdgeInsets.only(top: 3),
                                //                     child: Row(
                                //                         crossAxisAlignment:
                                //                             CrossAxisAlignment
                                //                                 .end,
                                //                         mainAxisAlignment:
                                //                             MainAxisAlignment
                                //                                 .end,
                                //                         children: <Widget>[
                                //                           Container(
                                //                             padding:
                                //                                 EdgeInsets.all(
                                //                                     2),
                                //                             decoration: BoxDecoration(
                                //                                 color:
                                //                                     mainColor,
                                //                                 borderRadius:
                                //                                     BorderRadius
                                //                                         .circular(
                                //                                             3)),
                                //                             child: Text(_day1,
                                //                                 style:
                                //                                     TextStyle(
                                //                                   fontSize: ScreenUtil
                                //                                           .getInstance()
                                //                                       .setSp(
                                //                                           MINI_FONT_SIZE),
                                //                                   color: white,
                                //                                 )),
                                //                           ),
                                //                           Padding(
                                //                             padding:
                                //                                 EdgeInsets.all(
                                //                                     3),
                                //                             child: Text("天",
                                //                                 style:
                                //                                     TextStyle(
                                //                                   fontSize: ScreenUtil
                                //                                           .getInstance()
                                //                                       .setSp(
                                //                                           MINI_FONT_SIZE),
                                //                                   color:
                                //                                       mainColor,
                                //                                 )),
                                //                           ),
                                //                           Container(
                                //                             padding:
                                //                                 EdgeInsets.all(
                                //                                     2),
                                //                             decoration: BoxDecoration(
                                //                                 color:
                                //                                     mainColor,
                                //                                 borderRadius:
                                //                                     BorderRadius
                                //                                         .circular(
                                //                                             3)),
                                //                             child: Text(_hour1,
                                //                                 style:
                                //                                     TextStyle(
                                //                                   fontSize: ScreenUtil
                                //                                           .getInstance()
                                //                                       .setSp(
                                //                                           MINI_FONT_SIZE),
                                //                                   color: white,
                                //                                 )),
                                //                           ),
                                //                           Padding(
                                //                             padding:
                                //                                 EdgeInsets.all(
                                //                                     3),
                                //                             child: Text(":",
                                //                                 style:
                                //                                     TextStyle(
                                //                                   fontSize: ScreenUtil
                                //                                           .getInstance()
                                //                                       .setSp(
                                //                                           MINI_FONT_SIZE),
                                //                                   color:
                                //                                       mainColor,
                                //                                 )),
                                //                           ),
                                //                           Container(
                                //                             padding:
                                //                                 EdgeInsets.all(
                                //                                     2),
                                //                             decoration: BoxDecoration(
                                //                                 color:
                                //                                     mainColor,
                                //                                 borderRadius:
                                //                                     BorderRadius
                                //                                         .circular(
                                //                                             3)),
                                //                             child: Text(
                                //                                 _minute1,
                                //                                 style:
                                //                                     TextStyle(
                                //                                   fontSize: ScreenUtil
                                //                                           .getInstance()
                                //                                       .setSp(
                                //                                           MINI_FONT_SIZE),
                                //                                   color: white,
                                //                                 )),
                                //                           ),
                                //                           Padding(
                                //                             padding:
                                //                                 EdgeInsets.all(
                                //                                     3),
                                //                             child: Text(":",
                                //                                 style:
                                //                                     TextStyle(
                                //                                   fontSize: ScreenUtil
                                //                                           .getInstance()
                                //                                       .setSp(
                                //                                           MINI_FONT_SIZE),
                                //                                   color:
                                //                                       mainColor,
                                //                                 )),
                                //                           ),
                                //                           Container(
                                //                             padding:
                                //                                 EdgeInsets.all(
                                //                                     2),
                                //                             decoration: BoxDecoration(
                                //                                 color:
                                //                                     mainColor,
                                //                                 borderRadius:
                                //                                     BorderRadius
                                //                                         .circular(
                                //                                             3)),
                                //                             child: Text(
                                //                                 _second1,
                                //                                 style:
                                //                                     TextStyle(
                                //                                   fontSize: ScreenUtil
                                //                                           .getInstance()
                                //                                       .setSp(
                                //                                           MINI_FONT_SIZE),
                                //                                   color: white,
                                //                                 )),
                                //                           ),
                                //                         ]))
                                //               ])),
                                //     ),
                                //     bottom: 0,
                                //     right: 0),
                              ],
                            ),
                            Container(
                              color: white,
                              alignment: Alignment.centerLeft,
                              child: Padding(
                                padding: EdgeInsets.fromLTRB(10, 10, 10, 5),
                                child: Text(goods_name,
                                    style: TextStyle(
                                      fontSize: ScreenUtil.getInstance()
                                          .setSp(NORMAL_FONT_SIZE + 2),
                                      color: black,
                                    )),
                              ),
                            ),
                            Offstage(
                              offstage: description == '',
                              child: Container(
                                color: white,
                                alignment: Alignment.centerLeft,
                                child: Padding(
                                  padding: EdgeInsets.fromLTRB(10, 0, 10, 5),
                                  child: Text(description,
                                      style: TextStyle(
                                        fontSize: ScreenUtil.getInstance()
                                            .setSp(NORMAL_FONT_SIZE),
                                        color: mainColor,
                                      )),
                                ),
                              ),
                            ),
                            Container(
                              color: white,
                              child: Padding(
                                padding: EdgeInsets.fromLTRB(10, 0, 10, 10),
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.start,
                                  crossAxisAlignment: CrossAxisAlignment.end,
                                  children: <Widget>[
                                    Text(
                                        (widget.type == 1 ? "抢购价 " : "") +
                                            MONEY,
                                        style: TextStyle(
                                          fontSize: ScreenUtil.getInstance()
                                              .setSp(SMALL_FONT_SIZE + 5),
                                          color: mainColor,
                                        )),
                                    Text(
                                        provider.selectedSkuModel == null
                                            ? widget.type == -1
                                                ? widget.price
                                                : price.toString()
                                            : provider.selectedSkuModel.price
                                                .toString(),
                                        style: TextStyle(
                                          fontSize: ScreenUtil.getInstance()
                                              .setSp(BIG_FONT_SIZE + 10),
                                          color: mainColor,
                                        )),
                                    Expanded(
                                      child: Text(
                                          widget.type == -1
                                              ? widget.old_price
                                              : old_price == null
                                                  ? ""
                                                  : old_price.toString(),
                                          style: TextStyle(
                                            decoration:
                                                TextDecoration.lineThrough,
                                            fontSize: ScreenUtil.getInstance()
                                                .setSp(NORMAL_FONT_SIZE),
                                            color: Colors.grey,
                                          )),
                                    ),
                                    Text("销量" + sales_num,
                                        style: TextStyle(
                                          fontSize: ScreenUtil.getInstance()
                                              .setSp(NORMAL_FONT_SIZE),
                                          color: Colors.grey,
                                        )),
                                  ],
                                ),
                              ),
                            ),
                            Offstage(
                              offstage: widget.type != 1,
                              child: Container(
                                  width: double.infinity,
                                  padding: EdgeInsets.fromLTRB(
                                      ScreenUtil.getInstance().setHeight(DP_15),
                                      0,
                                      0,
                                      (ScreenUtil.getInstance()
                                          .setHeight(DP_15))),
                                  color: white,
                                  child: Text(
                                      "共" +
                                          widget.all_num.toString() +
                                          "件   已抢" +
                                          widget.sale_num.toString() +
                                          "件",
                                      style: TextStyle(
                                        fontSize: ScreenUtil.getInstance()
                                            .setSp(SMALL_FONT_SIZE),
                                        color: Colors.black54,
                                      ))),
                            ),
                            Container(
                              height: 10,
                              color: divideColor,
                            ),
                            // Container(
                            //   height: 50,
                            //   padding: EdgeInsets.all(10),
                            //   color: white,
                            //   child: new GestureDetector(
                            //     behavior: HitTestBehavior.opaque,
                            //     onTap: () {
                            //       showGoodsAttributes(context);
                            //     },
                            //     child: new Row(
                            //       children: <Widget>[
                            //         Padding(
                            //           padding: EdgeInsets.fromLTRB(0, 0, 15, 0),
                            //           child: Text("促销活动",
                            //               style: TextStyle(
                            //                 color: black,
                            //                 fontSize: ScreenUtil.getInstance()
                            //                     .setSp(NORMAL_FONT_SIZE),
                            //               )),
                            //         ),
                            //         Container(
                            //           padding:
                            //               EdgeInsets.only(left: 5, right: 5),
                            //           margin:
                            //               EdgeInsets.only(left: 5, right: 5),
                            //           child: Text("满减",
                            //               style: TextStyle(
                            //                 color: mainColor,
                            //                 fontSize: ScreenUtil.getInstance()
                            //                     .setSp(NORMAL_FONT_SIZE - 5),
                            //               )),
                            //           decoration: BoxDecoration(
                            //               border: Border.all(
                            //                   color: mainColor, width: 1),
                            //               borderRadius:
                            //                   BorderRadius.circular(10)),
                            //         ),
                            //         // Text("每人限购" + widget.limit_num + "瓶/件",
                            //         //     style: TextStyle(
                            //         //       color: Colors.black54,
                            //         //       fontSize: ScreenUtil.getInstance()
                            //         //           .setSp(NORMAL_FONT_SIZE - 2),
                            //         //     )),
                            //       ],
                            //     ),
                            //   ),
                            // ),
                            // Offstage(
                            //   offstage: widget.type == 1 || widget.type == -1,
                            //   child: Container(
                            //     height: 10,
                            //     color: divideColor,
                            //   ),
                            // ),
                            // Offstage(
                            //   offstage: widget.type == 1 || widget.type == -1,
                            //   child: Container(
                            //     height: 50,
                            //     padding: EdgeInsets.all(10),
                            //     color: white,
                            //     child: new GestureDetector(
                            //       behavior: HitTestBehavior.opaque,
                            //       onTap: () {
                            //         showGoodsAttributes(context);
                            //       },
                            //       child: new Row(
                            //         children: <Widget>[
                            //           Padding(
                            //             padding:
                            //                 EdgeInsets.fromLTRB(0, 0, 15, 0),
                            //             child: Text("商品规格",
                            //                 style: TextStyle(
                            //                   color: black,
                            //                   fontSize: ScreenUtil.getInstance()
                            //                       .setSp(NORMAL_FONT_SIZE),
                            //                 )),
                            //           ),
                            //           Expanded(
                            //             child: Text(provider.selectedSku ?? '',
                            //                 style: TextStyle(
                            //                     color: black_99,
                            //                     fontSize:
                            //                         ScreenUtil.getInstance()
                            //                             .setSp(
                            //                                 NORMAL_FONT_SIZE),
                            //                     fontWeight: FontWeight.w500)),
                            //           ),
                            //           Icon(
                            //             Icons.arrow_forward_ios,
                            //             size: 15,
                            //           )
                            //         ],
                            //       ),
                            //     ),
                            //   ),
                            // ),
                            // // Container(
                            //   height: 10,
                            //   color: divideColor,
                            // ),
                            // Container(
                            //   color: white,
                            //   padding: EdgeInsets.all(
                            //       ScreenUtil.getInstance().setHeight(DP_20)),
                            //   child: Column(
                            //     children: <Widget>[
                            //       Row(
                            //         children: <Widget>[
                            //           Expanded(
                            //               child: Text('评价($comment_num)',
                            //                   style: TextStyle(
                            //                       color: Colors.black87,
                            //                       fontSize: ScreenUtil
                            //                               .getInstance()
                            //                           .setSp(
                            //                               NORMAL_FONT_SIZE)))),
                            //           Text('好评率$lvl1_cent%  ',
                            //               style: TextStyle(
                            //                   color: Colors.black54,
                            //                   fontSize: ScreenUtil.getInstance()
                            //                       .setSp(SMALL_FONT_SIZE))),
                            //           Icon(Icons.arrow_forward_ios,
                            //               color: Colors.black54, size: 15),
                            //         ],
                            //       ),
                            //       ListView.separated(
                            //         itemCount: commentList.length,
                            //         padding: EdgeInsets.all(0),
                            //         shrinkWrap: true,
                            //         physics: NeverScrollableScrollPhysics(),
                            //         itemBuilder:
                            //             (BuildContext context, int index) {
                            //           return new Container(
                            //             padding: EdgeInsets.only(top: 15),
                            //             child: Column(
                            //               crossAxisAlignment:
                            //                   CrossAxisAlignment.start,
                            //               children: <Widget>[
                            //                 Row(
                            //                   children: <Widget>[
                            //                     ClipOval(
                            //                         child: commentList[index]
                            //                                     .user_avatar ==
                            //                                 null
                            //                             ? Image.asset(
                            //                                 'images/app_icon.png',
                            //                                 width: ScreenUtil.getInstance()
                            //                                     .setHeight(
                            //                                         DP_50 + 10),
                            //                                 height: ScreenUtil.getInstance()
                            //                                     .setHeight(
                            //                                         DP_50 + 10))
                            //                             : CachedNetworkImage(
                            //                                 imageUrl: Api.ImgBaseUrl +
                            //                                     commentList[index]
                            //                                         .user_avatar,
                            //                                 fit: BoxFit.cover,
                            //                                 width: ScreenUtil.getInstance()
                            //                                     .setHeight(DP_50 + 10),
                            //                                 height: ScreenUtil.getInstance().setHeight(DP_50 + 10))),
                            //                     Container(width: 10),
                            //                     Column(
                            //                       crossAxisAlignment:
                            //                           CrossAxisAlignment.start,
                            //                       children: <Widget>[
                            //                         Text(
                            //                             commentList[index]
                            //                                 .user_nickname,
                            //                             style: TextStyle(
                            //                                 color:
                            //                                     Colors.black87,
                            //                                 fontSize: ScreenUtil
                            //                                         .getInstance()
                            //                                     .setSp(
                            //                                         NORMAL_FONT_SIZE +
                            //                                             3))),
                            //                         Container(
                            //                           height: 3,
                            //                         ),
                            //                         Text(
                            //                             commentList[index]
                            //                                 .comment_time,
                            //                             style: TextStyle(
                            //                                 color:
                            //                                     Colors.black54,
                            //                                 fontSize: ScreenUtil
                            //                                         .getInstance()
                            //                                     .setSp(
                            //                                         SMALL_FONT_SIZE -
                            //                                             3))),
                            //                       ],
                            //                     )
                            //                   ],
                            //                 ),
                            //                 Container(height: 10),
                            //                 Text(commentList[index].content,
                            //                     style: TextStyle(
                            //                         color: Colors.black,
                            //                         fontSize: ScreenUtil
                            //                                 .getInstance()
                            //                             .setSp(
                            //                                 NORMAL_FONT_SIZE -
                            //                                     3))),
                            //                 Container(height: 10),
                            //                 Container(
                            //                   height: 10 +
                            //                       (MediaQuery.of(context)
                            //                                   .size
                            //                                   .width -
                            //                               ScreenUtil
                            //                                       .getInstance()
                            //                                   .setHeight(
                            //                                       DP_80)) /
                            //                           3,
                            //                   child: GridView.builder(
                            //                     itemCount: commentList[index]
                            //                                 .imgList
                            //                                 .length >
                            //                             3
                            //                         ? 3
                            //                         : commentList[index]
                            //                             .imgList
                            //                             .length,
                            //                     shrinkWrap: true,
                            //                     physics:
                            //                         NeverScrollableScrollPhysics(),
                            //                     gridDelegate:
                            //                         SliverGridDelegateWithFixedCrossAxisCount(
                            //                             mainAxisSpacing:
                            //                                 ScreenUtil
                            //                                         .getInstance()
                            //                                     .setHeight(
                            //                                         DP_20),
                            //                             crossAxisSpacing: 10.0,
                            //                             crossAxisCount: 3),
                            //                     itemBuilder:
                            //                         (BuildContext context,
                            //                             int i) {
                            //                       return CachedNetworkImage(
                            //                           imageUrl: Api.ImgBaseUrl +
                            //                               commentList[index]
                            //                                   .imgList[i],
                            //                           height: (MediaQuery.of(
                            //                                           context)
                            //                                       .size
                            //                                       .width -
                            //                                   ScreenUtil
                            //                                           .getInstance()
                            //                                       .setHeight(
                            //                                           DP_80)) /
                            //                               3,
                            //                           fit: BoxFit.cover,
                            //                           width: (MediaQuery.of(
                            //                                           context)
                            //                                       .size
                            //                                       .width -
                            //                                   ScreenUtil
                            //                                           .getInstance()
                            //                                       .setHeight(
                            //                                           DP_80)) /
                            //                               3);
                            //                     },
                            //                   ),
                            //                 ),
                            //                 Text(commentList[index].sku,
                            //                     style: TextStyle(
                            //                         color: Colors.black54,
                            //                         fontSize: ScreenUtil
                            //                                 .getInstance()
                            //                             .setSp(SMALL_FONT_SIZE -
                            //                                 1))),
                            //                 Container(height: 10),
                            //               ],
                            //             ),
                            //           );
                            //         },
                            //         separatorBuilder:
                            //             (BuildContext context, int index) {
                            //           return Container(
                            //               height: 1, color: f0Color);
                            //         },
                            //       ),
                            //       GestureDetector(
                            //         child: Container(
                            //           padding:
                            //               EdgeInsets.fromLTRB(10, 2, 10, 2),
                            //           decoration: BoxDecoration(
                            //               border: Border.all(
                            //                   color: mainColor, width: 1),
                            //               borderRadius:
                            //                   BorderRadius.circular(30)),
                            //           child: Text('查看全部',
                            //               style: TextStyle(
                            //                   fontSize: ScreenUtil.getInstance()
                            //                       .setSp(SMALL_FONT_SIZE),
                            //                   color: mainColor)),
                            //         ),
                            //         onTap: () {
                            //           Fluttertoast.showToast(msg: "敬请期待");
                            //         },
                            //       )
                            //     ],
                            //   ),
                            // ),
                            // Container(
                            //   height: 10,
                            //   color: divideColor,
                            // ),
                            new Row(
                              children: <Widget>[
                                Expanded(
                                  child: Container(
                                    margin: EdgeInsets.fromLTRB(
                                        ScreenUtil.getInstance().setWidth(150),
                                        0,
                                        20,
                                        0),
                                    height: 1,
                                    color: Colors.grey,
                                  ),
                                ),
                                Text(
                                  "商品详情",
                                  textAlign: TextAlign.right,
                                  style: new TextStyle(
                                      color: Colors.grey, fontSize: 14),
                                ),
                                Expanded(
                                  child: Container(
                                    margin: EdgeInsets.fromLTRB(
                                        20,
                                        0,
                                        ScreenUtil.getInstance().setWidth(150),
                                        0),
                                    height: 1,
                                    color: Colors.grey,
                                  ),
                                ),
                              ],
                            ),
                            Container(
                              color: white,
                              padding: EdgeInsets.all(10),
                              margin: EdgeInsets.fromLTRB(0, 10, 0, 0),
                              child: Html(data: html),
                            )
                          ],
                        ),
                      ),
                    ),
                  )),
                ),
                Container(
                  color: white,
                  padding: EdgeInsets.fromLTRB(20, 2, 20, 30),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      // GestureDetector(
                      //   onTap: () {
                      //     doCollect();
                      //   },
                      //   behavior: HitTestBehavior.opaque,
                      //   child: new Column(
                      //     children: <Widget>[
                      //       Padding(
                      //         padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
                      //         child: Image.asset(
                      //             isCollectGoods
                      //                 ? 'images/icon_goodstab_collect_selected.png'
                      //                 : 'images/icon_goodstab_collect.png',
                      //             scale: 1.55),
                      //       ),
                      //       Text(isCollectGoods ? "已收藏" : '收藏',
                      //           style: TextStyle(
                      //               fontSize: ScreenUtil.getInstance()
                      //                   .setSp(SMALL_FONT_SIZE - 4)))
                      //     ],
                      //   ),
                      // ),
                      // Container(
                      //   width: 20,
                      // ),
                      // GestureDetector(
                      //   behavior: HitTestBehavior.opaque,
                      //   onTap: () {
                      //     Navigator.of(context)
                      //         .push(new MaterialPageRoute(builder: (context) {
                      //       return new ShopCarPage(type: 1);
                      //     }));
                      //   },
                      //   child: new Column(
                      //     children: <Widget>[
                      //       Padding(
                      //         padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
                      //         child: Image.asset(
                      //             'images/icon_goodstab_shoppingcart.png',
                      //             scale: 1.5),
                      //       ),
                      //       Text('购物车',
                      //           style: TextStyle(
                      //               fontSize: ScreenUtil.getInstance()
                      //                   .setSp(SMALL_FONT_SIZE - 4)))
                      //     ],
                      //   ),
                      // ),
                      // Offstage(
                      //   offstage: widget.type != null,
                      //   child: new Container(
                      //     margin: EdgeInsets.fromLTRB(0, 10, 0, 10),
                      //     height: ScreenUtil.getInstance().setHeight(50),
                      //     decoration: new BoxDecoration(
                      //         color: Colors.orangeAccent,
                      //         borderRadius: BorderRadius.circular(
                      //             ScreenUtil.getInstance().setHeight(5))),
                      //     child: new FlatButton(
                      //       child: new Padding(
                      //         padding: EdgeInsets.all(0.0),
                      //         child: new Text(
                      //           "加入购物车",
                      //           style: new TextStyle(
                      //               color: Colors.white,
                      //               fontSize: ScreenUtil.getInstance()
                      //                   .setSp(SMALL_FONT_SIZE)),
                      //         ),
                      //       ),
                      //       onPressed: () {
                      //         // Navigator.of(context).pop();
                      //         if (provider.selectedSku.contains("请选择") &&
                      //             hasSku == false) {
                      //           showGoodsAttributes(context);
                      //           return;
                      //         }
                      //         if (hasSku) {
                      //           addToCar("");
                      //           return;
                      //         }
                      //         List<Map> skuMap = List();
                      //         List<Goods> list = goodsDetailsModel.goods;
                      //         for (int i = 0; i < list.length; i++) {
                      //           Map goodsSku = new Map();
                      //           goodsSku['attribute_id'] = list[i].attribute_id;
                      //           var json = jsonDecode(
                      //               skuProvider.selectedSkuModel.sku);
                      //           var temp = "";
                      //           (json as List).forEach((v) {
                      //             temp += v["value"];
                      //           });
                      //           goodsSku['value'] = temp;
                      //           skuMap.add(goodsSku);
                      //         }
                      //         addToCar(json.encode(skuMap).toString());
                      //       },
                      //     ),
                      //   ),
                      // ),
                      // // new Container(
                      //   height: ScreenUtil.getInstance().setHeight(50),
                      //   decoration: new BoxDecoration(
                      //       color: Colors.orangeAccent,
                      //       borderRadius: BorderRadius.circular(
                      //           ScreenUtil.getInstance().setHeight(50))),
                      //   child: new FlatButton(
                      //     child: new Padding(
                      //       padding: EdgeInsets.all(0.0),
                      //       child: new Text(
                      //         "加入购物车",
                      //         style: new TextStyle(
                      //             color: Colors.white, fontSize: 14),
                      //       ),
                      //     ),
                      //     onPressed: () {
                      //       if (APPLIC.userInfoMap == null) {
                      //         Navigator.of(context).push(
                      //             new MaterialPageRoute(builder: (context) {
                      //           return new LoginPage();
                      //         }));
                      //         return;
                      //       }
                      //       if (APPLIC.userInfoMap['user_msg']['group_id'] ==
                      //           "1") {
                      //         Fluttertoast.showToast(msg: "请先升级成店主");
                      //         return;
                      //       }
                      //       if (provider.selectedSku.contains("请选择") &&
                      //           hasSku == false) {
                      //         showGoodsAttributes(context);
                      //       } else {
                      //         if (hasSku) {
                      //           addToCar("");
                      //           return;
                      //         }
                      //         List<Map> skuMap = List();
                      //         List<Goods> list = goodsDetailsModel.goods;
                      //         for (int i = 0; i < list.length; i++) {
                      //           Map goodsSku = new Map();
                      //           goodsSku['attribute_id'] = list[i].attribute_id;
                      //           goodsSku['value'] =
                      //               provider.selectedSkuModel.sku.split(";")[i];
                      //           skuMap.add(goodsSku);
                      //         }
                      //         addToCar(json.encode(skuMap).toString());

                      //         // // print(json.encode(skuMap).toString());
                      //         // Navigator.of(context)
                      //         //     .push(MaterialPageRoute(builder: (context) {
                      //         //   return BuyGoodsPage(
                      //         //     goods_id: widget.goods_id,
                      //         //     goods_name: goods_name,
                      //         //     goods_img: provider.selectedSkuModel.img,
                      //         //     price: provider.selectedSkuModel.price
                      //         //         .toString(),
                      //         //     skuJson: json.encode(skuMap).toString(),
                      //         //     skuInfo: provider.selectedSkuModel.sku,
                      //         //   );
                      //         // }));
                      //       }
                      //     },
                      //   ),
                      // ),
                      new Container(
                        margin: EdgeInsets.fromLTRB(0, 10, 0, 10),
                        height: ScreenUtil.getInstance().setHeight(60),
                        width:MediaQuery.of(context).size.width-50,
                        decoration: new BoxDecoration(
                           color:mainColor,
                            borderRadius: BorderRadius.circular(
                                ScreenUtil.getInstance().setHeight(8))),
                        child: new FlatButton(
                          child: new Padding(
                            padding: EdgeInsets.all(5.0),
                            child: new Text(
                              widget.type == 1 ? '立即抢购' : "购买升级",
                              style: new TextStyle(
                                  color: Colors.white,
                                  fontSize: ScreenUtil.getInstance()
                                      .setSp(SMALL_FONT_SIZE+4)),
                            ),
                          ),
                          onPressed: () {
                            if (provider.selectedSku.contains("请选择") &&
                                hasSku == true) {
                              showGoodsAttributes(context);
                            } else {
                              if (!hasSku) {
                                if ("N" == is_send) {
                                  showDialog(
                                      context: context,
                                      barrierDismissible: false,
                                      builder: (_) {
                                        return new NetLoadingDialog(
                                          loadingText: "下单中...",
                                          bgColor: Color.fromARGB(255, 0, 0, 0),
                                          requestCallBack: null,
                                          outsideDismiss: false,
                                        );
                                      });
                                  buy();
                                  return;
                                }
                                Navigator.of(context).push<Map>(
                                    MaterialPageRoute(builder: (context) {
                                  return BuyGoodsPage(
                                    old: old_price,
                                    is_vip: "1",
                                    // fs: widget.type == -1
                                    //     ? "5"
                                    //     : widget.type == 1 ? "1" : '0',
                                    id: widget.id,
                                    goods_num: goods_num.toString(),
                                    goods_id: widget.goods_id,
                                    goods_name: goods_name,
                                    goods_img: gallery[0].img,
                                    type: widget.type.toString(),
                                    price: widget.type == -1
                                        ? widget.price
                                        : price.toString(),
                                    skuJson: "",
                                    skuInfo: "",
                                  );
                                })).then((value) {
                                  if (value != null) {
                                    Navigator.of(context).push<String>(
                                        MaterialPageRoute(builder: (context) {
                                      return new VipOrderPayPage(
                                          orderId: value['data']['order_id'],
                                          title: value['data']['title'],
                                          orderNum: value['data']['order_num'],
                                          totalMoney: value['data']['pay_price']
                                              .toString());
                                    })).then((value) {
                                      if (value != null) {
                                        // APPLIC.HH = 1;
                                        // Navigator.of(context).push(
                                        //     new MaterialPageRoute(
                                        //         builder: (context) {
                                        //   return new OrderPage();
                                        // }));
                                      }
                                    });
                                  }
                                  // Navigator.of(context).pop();
                                });
                                return;
                              }
                              List<Map> skuMap = List();
                              List<Goods> list = goodsDetailsModel.goods;
                              for (int i = 0; i < list.length; i++) {
                                Map goodsSku = new Map();
                                goodsSku['attribute_id'] = list[i].attribute_id;
                                var json =
                                    jsonDecode(provider.selectedSkuModel.sku);
                                var temp = "";
                                (json as List).forEach((v) {
                                  temp += v["value"];
                                });
                                goodsSku['value'] = temp;
                                skuMap.add(goodsSku);
                              }
                              // print(json.encode(skuMap).toString());
                              Navigator.of(context).push<Map>(
                                  MaterialPageRoute(builder: (context) {
                                return BuyGoodsPage(
                                  old: old_price,
                                  is_vip: "1",
                                  goods_num: goods_num.toString(),
                                  type: widget.type.toString(),
                                  goods_id: widget.goods_id,
                                  goods_name: goods_name,
                                  id: widget.id,
                                  goods_img: provider.selectedSkuModel.img,
                                  price: widget.type == -1
                                      ? widget.price
                                      : provider.selectedSkuModel.price
                                          .toString(),
                                  skuJson: json.encode(skuMap).toString(),
                                  skuInfo: provider.selectedSkuModel.sku,
                                );
                              })).then((value) {
                                if (value != null) {
                                  Navigator.of(context).push<String>(
                                      MaterialPageRoute(builder: (context) {
                                    return new VipOrderPayPage(
                                        orderId: value['data']['order_id'],
                                        title: value['data']['title'],
                                        orderNum: value['data']['order_num'],
                                        totalMoney: value['data']['pay_price']
                                            .toString());
                                  })).then((value) {
                                    if (value != null) {
                                      // APPLIC.HH = 1;
                                      // Navigator.of(context).push(
                                      //     new MaterialPageRoute(
                                      //         builder: (context) {
                                      //   return new OrderPage();
                                      // }));
                                    }
                                  });
                                }
                                // Navigator.of(context).pop();
                              });
                            }
                          },
                        ),
                      )
                    ],
                  ),
                )
              ],
            );
          })),
    );
  }

  showGoodsAttributes(BuildContext context) {
    showModalBottomSheet(
        context: context,
        backgroundColor: Colors.transparent,
        builder: (BuildContext context) {
          return StatefulBuilder(
            builder: (BuildContext context, setState) {
              return new Container(
                height: MediaQuery.of(context).size.height * 2 / 3,
                alignment: AlignmentDirectional.center,
                padding: EdgeInsets.fromLTRB(20, 0, 10, 10),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(15),
                      topRight: Radius.circular(15),
                    ),
                    color: white),
                child: new Column(
                  children: <Widget>[
                    new Row(
                      mainAxisAlignment: MainAxisAlignment.end,
                      children: <Widget>[
                        GestureDetector(
                          onTap: () {
                            Navigator.of(context).pop();
                          },
                          child: Container(
                            width: 50,
                            color: white,
                            height: 50,
                            child: Image.asset('images/icon_close.png'),
                          ),
                        )
                      ],
                    ),
                    Expanded(
                      flex: 1,
                      child: SingleChildScrollView(
                        child: ChangeNotifierProvider.value(
                            value: skuProvider,
                            child: SkuDialog(
                              goods_name: goods_name,
                              initPrice: price.toString(),
                              img: gallery[0].img,
                            )),
                      ),
                    ),
                    Row(
                      children: <Widget>[
                        Expanded(
                          child: Text('数量',
                              maxLines: 1,
                              style: TextStyle(
                                  fontSize: ScreenUtil.getInstance()
                                      .setSp(SMALL_FONT_SIZE),
                                  color: black)),
                        ),
                        GestureDetector(
                          child: Icon(
                            Icons.remove,
                            color: black,
                            size: ScreenUtil.getInstance().setHeight(DP_30),
                          ),
                          onTap: () {
                            if (goods_num == 1) {
                              return;
                            }
                            goods_num--;
                            setState(() {});
                          },
                        ),
                        Container(
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(2),
                              color: f0Color),
                          padding: EdgeInsets.fromLTRB(
                              ScreenUtil.getInstance().setHeight(DP_20),
                              2,
                              ScreenUtil.getInstance().setHeight(DP_20),
                              2),
                          margin: EdgeInsets.fromLTRB(
                              ScreenUtil.getInstance().setHeight(DP_10),
                              0,
                              ScreenUtil.getInstance().setHeight(DP_10),
                              0),
                          child: Text(
                            goods_num.toString(),
                            style: TextStyle(
                                fontSize: ScreenUtil.getInstance()
                                    .setSp(SMALL_FONT_SIZE),
                                color: Colors.black87),
                          ),
                        ),
                        GestureDetector(
                          child: Icon(
                            Icons.add,
                            size: ScreenUtil.getInstance().setHeight(DP_30),
                            color: black,
                          ),
                          onTap: () {
                            goods_num++;
                            setState(() {});
                          },
                        )
                      ],
                    ),
                    Container(
                      height: 10,
                    ),
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                       new Container(
                          height: ScreenUtil.getInstance().setHeight(60),
                          margin: EdgeInsets.fromLTRB(20, 20, 20, 30),
                          width: MediaQuery.of(context).size.width-80,
                          decoration: new BoxDecoration(
                               color:mainColor,
                              borderRadius: BorderRadius.circular(
                                  ScreenUtil.getInstance().setHeight(5))),
                          child: new FlatButton(
                            child: new Padding(
                              padding: EdgeInsets.all(0.0),
                              child: new Text(
                                "购买升级",
                                style: new TextStyle(
                                    color: Colors.white,
                                    fontSize: ScreenUtil.getInstance()
                                        .setSp(NORMAL_FONT_SIZE+2)),
                              ),
                            ),
                            onPressed: () {
                              if (hasSku) {
                                Navigator.of(context).push<Map>(
                                    MaterialPageRoute(builder: (context) {
                                  return BuyGoodsPage(
                                    goods_id: widget.goods_id,
                                    is_vip: "1",
                                    type: widget.type.toString(),
                                    goods_name: goods_name,
                                    goods_num: goods_num.toString(),
                                    goods_img: gallery[0].img,
                                    price: price.toString(),
                                    skuJson: "",
                                    id: widget.id,
                                    skuInfo: "无配置",
                                    old: old_price,
                                  );
                                })).then((value) {
                                  if (value != null) {
                                    Navigator.of(context).push<String>(
                                        MaterialPageRoute(builder: (context) {
                                      return new VipOrderPayPage(
                                          orderId: value['data']['order_id'],
                                          title: value['data']['title'],
                                          orderNum: value['data']['order_num'],
                                          totalMoney: value['data']['pay_price']
                                              .toString());
                                    })).then((value) {
                                      if (value != null) {
                                        // APPLIC.HH = 1;
                                        // Navigator.of(context).push(
                                        //     new MaterialPageRoute(
                                        //         builder: (context) {
                                        //   return new OrderPage();
                                        // }));
                                      }
                                    });
                                  }
                                  // Navigator.of(context).pop();
                                });
                                return;
                              }
                              List<Map> skuMap = List();
                              List<Goods> list = goodsDetailsModel.goods;
                              for (int i = 0; i < list.length; i++) {
                                Map goodsSku = new Map();
                                goodsSku['attribute_id'] = list[i].attribute_id;
                                // goodsSku['value'] = skuProvider
                                //     .selectedSkuModel.sku
                                //     .split(";")[i];
                                var json = jsonDecode(
                                    skuProvider.selectedSkuModel.sku);
                                var temp = "";
                                (json as List).forEach((v) {
                                  temp += v["value"];
                                });
                                goodsSku['value'] = temp;
                                skuMap.add(goodsSku);
                              }
                              // print(json.encode(skuMap).toString());
                              Navigator.of(context).push<Map>(
                                  MaterialPageRoute(builder: (context) {
                                return BuyGoodsPage(
                                  goods_num: goods_num.toString(),
                                  goods_id: widget.goods_id,
                                  old: old_price,
                                  is_vip: "1",
                                  type: widget.type.toString(),
                                  goods_name: goods_name,
                                  goods_img: skuProvider.selectedSkuModel.img,
                                  price: skuProvider.selectedSkuModel.price
                                      .toString(),
                                  id: widget.id,
                                  skuJson: json.encode(skuMap).toString(),
                                  skuInfo: skuProvider.selectedSkuModel.sku,
                                );
                              })).then((value) {
                                if (value != null) {
                                  Navigator.of(context).push<String>(
                                      MaterialPageRoute(builder: (context) {
                                    return new VipOrderPayPage(
                                        orderId: value['data']['order_id'],
                                        title: value['data']['title'],
                                        orderNum: value['data']['order_num'],
                                        totalMoney: value['data']['pay_price']
                                            .toString());
                                  })).then((value) {
                                    if (value != null) {
                                      // Navigator.of(context).push(
                                      //     new MaterialPageRoute(
                                      //         builder: (context) {
                                      //   return new OrderPage();
                                      // }));
                                    }
                                  });
                                }
                                // Navigator.of(context).pop();
                              });
                              // Navigator.of(context).pop();
                            },
                          ),
                        )
                      ],
                    ),
                  ],
                ),
              );
            },
          );
        });
  }

  Map userMap = null;

  buy() async {
    Map map = new Map();
    map['token'] = token;
    map['goods_id'] = widget.goods_id;
    map['sign_type'] = SignType.BUY_GOODS;
    Response<String> response = await HttpUtil().post(
        Api.BaseUrl + "/index.php/wap/UserOrder/order",
        data: getSign(map));
    userMap = json.decode(response.data);
    int code = userMap['code'];
    Navigator.of(context).pop(1);
    if (code == 1) {
      Fluttertoast.showToast(msg: '下单成功');
      Navigator.of(context).push(MaterialPageRoute(builder: (context) {
        return new VipOrderPayPage(
            orderId: userMap['data']['order_id'].toString(),
            title: userMap['data']['title'],
            orderNum: userMap['data']['order_num'],
            totalMoney: userMap['data']['pay_price'].toString());
      }));
    } else {
      Fluttertoast.showToast(msg: userMap['msg']);
      userMap = null;
    }
  }

  addToCar(String attr) async {
    Map map = new Map();
    map['token'] = token;
    map['goods_id'] = widget.goods_id;
    map['sign_type'] = SignType.ADD_SHOP_CAR;
    map['goods_num'] = goods_num;
    if (attr != "") map['goods_sku'] = attr;
    Response<String> response =
        await HttpUtil().post(Api.ADD_SHOP_CAR, data: getSign(map));
    Map userMap = json.decode(response.data);
    int code = userMap['code'];
    Fluttertoast.showToast(msg: userMap['msg']);
    if (code == 1 && mounted) {}
  }
}
